/*
* @Author: steven.wang
* @Date:   2019-03-21 13:56:28
* @Last Modified by:   steven.wang
* @Last Modified time: 2019-05-15 10:40:57
*/
const DivideModel = require('../../models/crawler/divide');
/**
 * 查询行政区块列表
 * @author steven.wang
 * @DateTime 2019-03-04T13:57:18+0800
 */
exports.list = async (req, res) => {
	req.query.type = req.query.type || 'country';
	let divide = await DivideModel.list(req.query);
	let count = await DivideModel.count(req.query);
	res.json({
		success: true,
		msg: '',
		data: {
			page: req.query.page || 1,
			pageSize: req.query.pageSize || 10,
			total: count[0]['count(*)'],
			list: divide
		}
	})
}
/**
 * 根据省份code获取其城市列表
 * @author steven.wang
 * @DateTime 2019-03-21T17:03:33+0800
 */
exports.getCitysByProvinceCode = async (req, res) => {
	let citys = await DivideModel.getCitysByProvinceCode(req.query);
	res.json({
		success: true,
		msg: '',
		data: citys
	})
}
/**
 * 根据城市code获取县/区列表
 * @author steven.wang
 * @DateTime 2019-03-22T14:45:52+0800
 */
exports.getCountysByCityCode = async (req, res) => {
	let countys = await DivideModel.getCountysByCityCode(req.query);
	res.json({
		success: true,
		msg: '',
		data: countys
	})
}
/**
 * 根据县/区code获取乡镇列表
 * @author steven.wang
 * @DateTime 2019-03-22T15:24:58+0800
 */
exports.getTownsByCountyCode = async (req, res) => {
	let towns = await DivideModel.getTownsByCountyCode(req.query);
	res.json({
		success: true,
		msg: '',
		data: towns
	})
}
/**
 * 根据乡镇code获取社区列表
 * @author steven.wang
 * @DateTime 2019-03-22T15:38:31+0800
 */
exports.getVillagesByTownCode = async (req, res) => {
	let villages = await DivideModel.getVillagesByTownCode(req.query);
	res.json({
		success: true,
		msg: '',
		data: villages
	})
}